import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dings
 * Date: 2024-06-25
 * Time: 14:17
 */
public class Test {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);

        int size = list.size();
        ListIterator<Integer> listIterator = list.listIterator(size);
        while (listIterator.hasPrevious()) {
            int data = listIterator.previous();
            System.out.print(data+" ");
        }
    }
    public static void main10(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);

        ListIterator<Integer> listIterator = list.listIterator();
        while (listIterator.hasNext()) {
            int data = listIterator.next();
            System.out.println(data+" ");
        }
    }
    public static void main9(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);

        Iterator<Integer> iterator =  list.iterator();
        while (iterator.hasNext()) {//hasNext方法 用来判断是否有下一个数据
            int data = iterator.next();//next方法是 得到下一个数据
            System.out.print(data+" ");
        }
    }
    public static void main8(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        for (int data : list) {
            System.out.print(data+" ");
        }
    }
    public static void main7(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        int size = list.size();
        for (int i = 0; i < size; i++) {
            int data = list.get(i);//得到i下标的元素
            System.out.print(data+" ");
        }
        System.out.println();
    }
    public static void main6(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(11);
        list.add(22);
        list.add(33);
        list.add(44);

        List<Integer> list1 = list.subList(1,3);//[1,3) list1: 22 , 33

        System.out.println(list1);
    }
    public static void main5(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(11);
        list.add(22);
        list.add(33);
        list.add(44);

        ArrayList<Integer> list1 = new ArrayList<>();
        list1.add(1000);
        list1.addAll(list);

        System.out.println("顺序表list1:"+list1);
    }
    public static void main4(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(11);
        list.add(22);
        list.add(33);
        list.add(44);

        list.remove(new Integer(22));
        System.out.println(list);
    }
    public static void main3(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);

        int a = list.remove(2);//3
        System.out.println(a);

        System.out.println(list);//1 2
    }
    public static void main2(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);

        //在 1下标 位置处插入数据00
        list.add(1,100);



        System.out.println(list);
    }
    public static void main1(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        ArrayList<Integer> list1 = new ArrayList<>(list);//将list当做顺序表构造方法的参数传入
        list1.add(99);
        list1.add(100);
        System.out.println(list1);//[1, 2, 3, 99, 100]
    }
}
